In [4]:
import graphlab as gl
In [7]:
image_train = gl.SFrame('image_train_data/')
In [5]:
knn_model = gl.nearest_neighbors.create(image_train, features=['deep_features'],
label = 'id')
In [13]:
gl.canvas.set_target('ipynb')
cat = image_train[18:19]
cat['image'].show()
In [8]:
knn_model.query(cat)
Out[8]:
In [11]:
def get_images_from_ids(query_result):
return image_train.filter_by(query_result['reference_label'], 'id')
In [14]:
cat_neighbors = get_images_from_ids(knn_model.query(cat))
In [19]:
cat_neighbors['image'].show()
In [20]:
car = image_train[8:9]
In [21]:
car['image'].show()
In [22]:
get_images_from_ids(knn_model.query(car))['image'].show()
In [23]:
show_neighbors = lambda i:get_images_from_ids(knn_model.query(image_train[i:i+1]))['image'].show()
In [26]:
show_neighbors(19)
In [28]:
show_neighbors(1222)
In [30]:
show_neighbors(2000)
In [33]:
image_train['label'].sketch_summary()
Out[33]:
In [ ]:
In [35]:
dog_image_train = image_train[image_train['label']=='dog']
In [69]:
cat_image_train = image_train[image_train['label']=='cat']
##cat_image_train.head()
In [70]:
auto_image_train = image_train[image_train['label']=='automobile']
In [71]:
bird_image_train = image_train[image_train['label']=='bird']
In [41]:
dog_model = gl.nearest_neighbors.create(dog_image_train,
features = ['deep_features'],
label = 'id')
In [43]:
image_test = gl.SFrame('image_test_data/')
In [44]:
cat_model = gl.nearest_neighbors.create(cat_image_train,
features = ['deep_features'],
label = 'id')
In [45]:
auto_model = gl.nearest_neighbors.create(auto_image_train,
features = ['deep_features'],
label = 'id')
In [46]:
bird_model = gl.nearest_neighbors.create(bird_image_train,
features = ['deep_features'],
label = 'id')
In [57]:
query_result_cat = cat_model.query(image_test[0:1])
cat_image_train.filter_by(query_result_cat['reference_label'], 'id')['image'].show()
In [61]:
query_result_dog = dog_model.query(image_test[0:1])
dog_image_train.filter_by(query_result_dog['reference_label'], 'id')['label']
Out[61]:
In [ ]:
In [63]:
## mean to
query_result_cat['distance'].mean()
Out[63]:
In [76]:
query_result_dog['distance'].mean()
query_result_dog
Out[76]:
In [ ]:
In [65]:
cat_test_image = image_test[image_test['label']=='cat']
In [66]:
dog_test_image = image_test[image_test['label']=='dog']
In [72]:
auto_test_image = image_test[image_test['label']=='automobile']
bird_test_image = image_test[image_test['label']=='bird']
In [ ]:
In [ ]: